from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-08-16 14:26:04.400507
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 16, Aug, 2021
Time: 14:26:09
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -45.6678
Nobs: 385.000 HQIC: -46.2255
Log likelihood: 4142.33 FPE: 5.82654e-21
AIC: -46.5920 Det(Omega_mle): 4.62576e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.438206 0.095884 4.570 0.000
L1.Burgenland 0.111504 0.049756 2.241 0.025
L1.Kärnten -0.115897 0.024450 -4.740 0.000
L1.Niederösterreich 0.171227 0.106762 1.604 0.109
L1.Oberösterreich 0.119441 0.105470 1.132 0.257
L1.Salzburg 0.290197 0.051775 5.605 0.000
L1.Steiermark 0.015963 0.068636 0.233 0.816
L1.Tirol 0.119961 0.054142 2.216 0.027
L1.Vorarlberg -0.116053 0.048859 -2.375 0.018
L1.Wien -0.028063 0.094467 -0.297 0.766
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const -0.002012 0.225731 -0.009 0.993
L1.Burgenland -0.049107 0.117135 -0.419 0.675
L1.Kärnten 0.035029 0.057561 0.609 0.543
L1.Niederösterreich -0.252650 0.251339 -1.005 0.315
L1.Oberösterreich 0.550736 0.248299 2.218 0.027
L1.Salzburg 0.315005 0.121888 2.584 0.010
L1.Steiermark 0.113748 0.161583 0.704 0.481
L1.Tirol 0.301313 0.127461 2.364 0.018
L1.Vorarlberg -0.012727 0.115025 -0.111 0.912
L1.Wien 0.013257 0.222395 0.060 0.952
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.254381 0.048879 5.204 0.000
L1.Burgenland 0.096688 0.025364 3.812 0.000
L1.Kärnten -0.003339 0.012464 -0.268 0.789
L1.Niederösterreich 0.233132 0.054424 4.284 0.000
L1.Oberösterreich 0.155435 0.053765 2.891 0.004
L1.Salzburg 0.037207 0.026393 1.410 0.159
L1.Steiermark 0.009660 0.034988 0.276 0.782
L1.Tirol 0.074055 0.027600 2.683 0.007
L1.Vorarlberg 0.057226 0.024907 2.298 0.022
L1.Wien 0.086409 0.048156 1.794 0.073
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.191967 0.047780 4.018 0.000
L1.Burgenland 0.043569 0.024794 1.757 0.079
L1.Kärnten -0.006616 0.012184 -0.543 0.587
L1.Niederösterreich 0.123705 0.053200 2.325 0.020
L1.Oberösterreich 0.313346 0.052557 5.962 0.000
L1.Salzburg 0.101795 0.025800 3.946 0.000
L1.Steiermark 0.138808 0.034202 4.059 0.000
L1.Tirol 0.076114 0.026979 2.821 0.005
L1.Vorarlberg 0.055012 0.024347 2.260 0.024
L1.Wien -0.038626 0.047074 -0.821 0.412
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.207314 0.095453 2.172 0.030
L1.Burgenland -0.062025 0.049532 -1.252 0.210
L1.Kärnten -0.036347 0.024340 -1.493 0.135
L1.Niederösterreich 0.083324 0.106282 0.784 0.433
L1.Oberösterreich 0.198682 0.104996 1.892 0.058
L1.Salzburg 0.264287 0.051542 5.128 0.000
L1.Steiermark 0.074598 0.068327 1.092 0.275
L1.Tirol 0.124118 0.053899 2.303 0.021
L1.Vorarlberg 0.115235 0.048640 2.369 0.018
L1.Wien 0.035054 0.094042 0.373 0.709
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.027272 0.074679 0.365 0.715
L1.Burgenland 0.028808 0.038752 0.743 0.457
L1.Kärnten 0.050660 0.019043 2.660 0.008
L1.Niederösterreich 0.198219 0.083151 2.384 0.017
L1.Oberösterreich 0.346904 0.082145 4.223 0.000
L1.Salzburg 0.046933 0.040325 1.164 0.244
L1.Steiermark -0.001936 0.053457 -0.036 0.971
L1.Tirol 0.114318 0.042168 2.711 0.007
L1.Vorarlberg 0.061432 0.038054 1.614 0.106
L1.Wien 0.128818 0.073575 1.751 0.080
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.177772 0.090883 1.956 0.050
L1.Burgenland 0.022967 0.047160 0.487 0.626
L1.Kärnten -0.057652 0.023175 -2.488 0.013
L1.Niederösterreich -0.114183 0.101193 -1.128 0.259
L1.Oberösterreich 0.191829 0.099969 1.919 0.055
L1.Salzburg 0.031341 0.049074 0.639 0.523
L1.Steiermark 0.300710 0.065056 4.622 0.000
L1.Tirol 0.493910 0.051318 9.625 0.000
L1.Vorarlberg 0.065694 0.046311 1.419 0.156
L1.Wien -0.109230 0.089539 -1.220 0.223
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.163652 0.099128 1.651 0.099
L1.Burgenland -0.004451 0.051439 -0.087 0.931
L1.Kärnten 0.062696 0.025277 2.480 0.013
L1.Niederösterreich 0.193779 0.110373 1.756 0.079
L1.Oberösterreich -0.120913 0.109038 -1.109 0.267
L1.Salzburg 0.244824 0.053526 4.574 0.000
L1.Steiermark 0.153284 0.070958 2.160 0.031
L1.Tirol 0.052227 0.055974 0.933 0.351
L1.Vorarlberg 0.121313 0.050512 2.402 0.016
L1.Wien 0.136756 0.097663 1.400 0.161
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.494835 0.053765 9.204 0.000
L1.Burgenland -0.016302 0.027899 -0.584 0.559
L1.Kärnten -0.009410 0.013710 -0.686 0.492
L1.Niederösterreich 0.197615 0.059864 3.301 0.001
L1.Oberösterreich 0.261862 0.059140 4.428 0.000
L1.Salzburg 0.020859 0.029032 0.718 0.472
L1.Steiermark -0.024701 0.038486 -0.642 0.521
L1.Tirol 0.068205 0.030359 2.247 0.025
L1.Vorarlberg 0.058244 0.027397 2.126 0.034
L1.Wien -0.048888 0.052970 -0.923 0.356
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.019143 0.066256 0.138105 0.126496 0.038966 0.066202 -0.002181 0.185287
Kärnten 0.019143 1.000000 -0.055976 0.128837 0.045350 0.069069 0.458106 -0.093947 0.098582
Niederösterreich 0.066256 -0.055976 1.000000 0.290452 0.090576 0.272711 0.013864 0.148420 0.255175
Oberösterreich 0.138105 0.128837 0.290452 1.000000 0.175181 0.295003 0.164105 0.119938 0.134577
Salzburg 0.126496 0.045350 0.090576 0.175181 1.000000 0.129861 0.049926 0.108837 0.051422
Steiermark 0.038966 0.069069 0.272711 0.295003 0.129861 1.000000 0.127477 0.087373 -0.022580
Tirol 0.066202 0.458106 0.013864 0.164105 0.049926 0.127477 1.000000 0.038200 0.122584
Vorarlberg -0.002181 -0.093947 0.148420 0.119938 0.108837 0.087373 0.038200 1.000000 -0.047975
Wien 0.185287 0.098582 0.255175 0.134577 0.051422 -0.022580 0.122584 -0.047975 1.000000